<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  class bm_facebook {
    var $code = 'bm_facebook';
    var $group = 'boxes';
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function bm_facebook() {
      $this->title = MODULE_BOXES_FACEBOOK_TITLE;
      $this->description = MODULE_BOXES_FACEBOOK_DESCRIPTION;

      if ( defined('MODULE_BOXES_FACEBOOK_STATUS') ) {
        $this->sort_order = MODULE_BOXES_FACEBOOK_SORT_ORDER;
        $this->enabled = (MODULE_BOXES_FACEBOOK_STATUS == 'True');

        $this->group = ((MODULE_BOXES_FACEBOOK_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
      }
    }

    function execute() {
      global $oscTemplate;
 
		$data = '<div class="blk_sty">'.
					'<h1 class="title_blk_sty">' . MODULE_BOXES_FACEBOOK_BOX_TITLE . '<!-- <span class="taileft"> </span> <span class="tairight"> </span>--></h1>'.
					'<div class="main_blk_sty">'.
						'<div class="clear"> </div>'.
						'<div id="fb-root"></div>
						<script>(function(d, s, id) {
						  var js, fjs = d.getElementsByTagName(s)[0];
						  if (d.getElementById(id)) return;
						  js = d.createElement(s); js.id = id;
						  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
						  fjs.parentNode.insertBefore(js, fjs);
						}(document, "script", "facebook-jssdk"));</script>'.
						'<div class="fb-like-box" data-href="http://www.facebook.com/nuochoagiasi.vn" data-width="236" data-show-faces="true" data-colorscheme="light" data-stream="true" data-header="true"></div>'.
					'</div>'.					
				'</div>';	

      $oscTemplate->addBlock($data, $this->group);
    }

    function isEnabled() {
      return $this->enabled;
    }

    function check() {
      return defined('MODULE_BOXES_FACEBOOK_STATUS');
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable FACEBOOK Module', 'MODULE_BOXES_FACEBOOK_STATUS', 'True', 'Do you want to add the module to your shop?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Content Placement', 'MODULE_BOXES_FACEBOOK_CONTENT_PLACEMENT', 'Left Column', 'Should the module be loaded in the left or right column?', '6', '1', 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_BOXES_FACEBOOK_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_BOXES_FACEBOOK_STATUS', 'MODULE_BOXES_FACEBOOK_CONTENT_PLACEMENT', 'MODULE_BOXES_FACEBOOK_SORT_ORDER');
    }
  }
?>
